# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :thread_pool_test.py
# @Time      :2025/7/7 21:16
# @Author    :aiyimu

from concurrent.futures import ThreadPoolExecutor
import time


def task(name):
    print(f"任务{name}开始")
    time.sleep(2)
    print(f"任务{name}结束")
    return f"结果{name}"


# 创建线程池（最多3个线程）
with ThreadPoolExecutor(max_workers=3) as executor:
    # 提交任务
    futures = [executor.submit(task, i) for i in range(5)]

    # 获取结果
    for future in futures:
        print(future.result())

print("所有任务完成")